# coding=utf-8
import RPi.GPIO as GPIO
import time


class Steering:
    def __init__(self, ServoPin):
        GPIO.setup(ServoPin, GPIO.OUT)
        self.ServoPin = ServoPin

    def servo_control(self, angle):
        """
        定义一个脉冲函数，用来模拟方式产生pwm值,时基脉冲为20ms，
        该脉冲高电平部分在0.5-2.5ms控制0-180度
        :param angle:
        :return:
        """
        width = (angle * 11) + 500
        GPIO.output(self.ServoPin, GPIO.HIGH)
        time.sleep(width / 1000000.0)
        GPIO.output(self.ServoPin, GPIO.LOW)
        time.sleep(20.0 / 1000 - width / 1000000.0)



